package com.jboost.modules.app.service.strategry.hs;

import com.google.common.collect.Maps;
import com.jboost.common.util.EncryptSha256Util;
import com.jboost.common.util.HttpRestUtils;
import com.jboost.common.util.JSONUtil;
import com.jboost.modules.app.constant.Strategy;
import com.jboost.modules.app.dto.XmFieldDto;
import com.jboost.modules.monitor.service.RedisService;
import com.jboost.modules.system.mapper.HsMaterialNeedMapper;
import com.jboost.modules.system.mapper.SysUserDepartMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

@Service
@Slf4j
public abstract class AbstractHsMateria<T, V> implements Strategy<T,V> {

    @Autowired
    StringRedisTemplate redisTemplate;
    protected HttpHeaders jdyHeaders;
    {
        jdyHeaders = new HttpHeaders();
        jdyHeaders.set("Authorization","Bearer "+ "smLHulipnrxt6Lx9x1GqA0CyzpSl4k2o");

    }

    public HttpHeaders getJdyHeaders(){
        HttpHeaders jdyHeaders = new HttpHeaders();
        jdyHeaders.set("Authorization","Bearer "+ "smLHulipnrxt6Lx9x1GqA0CyzpSl4k2o");
        return jdyHeaders;
    }
    @Autowired
    protected HsMaterialNeedMapper hsMaterialNeedMapper;
    protected final static String app_id = "63a2b7b0317aeb00084ff740";
    protected final static String form_id = "63b8011fd1811400089d140d";


//    protected Map<String, XmFieldDto.DataBean> getFieldsSelectMap(String field) throws IOException {
//        HttpHeaders headers = new HttpHeaders();
//        HashMap<String, Object> paramMap = Maps.newHashMap();
//        paramMap.put("field",field);
//        headers.set("Authorization","Basic "+ Base64.getEncoder().encodeToString((client_id+":"+client_secret).getBytes()));
//        String response = HttpRestUtils.get(select_api, paramMap, headers);
//        XmFieldDto xmFieldDto = JSONUtil.fromJson(response, XmFieldDto.class);
//        Map<String, XmFieldDto.DataBean> collect = xmFieldDto.getData().stream().collect(Collectors.toMap(XmFieldDto.DataBean::getId, Function.identity(), (a, b) -> a));
//        return collect;
//
//    }




    public HashMap<String, Object> getParam() {
        HashMap<String, Object> paramMap = Maps.newHashMap();
        paramMap.put("app_id",getAppId());
        paramMap.put("entry_id",getFormId());
        return paramMap;
    };
}
